package paiement;

import java.io.IOException;
import java.util.Calendar;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;


// Referenced classes of package gouv.education.apoweb.servlet.etapes:
//            LogicWebCalculDroitsComplementaires, LogicWebDroits, LogicWebCalculDroits, LogicWebPaiementExterieur

public class LogicWebEtapesAction extends DispatchAction
{

    private static Log logger = LogFactory.getLog(LogicWebEtapesAction.class);

    public ActionForward paiement(ActionMapping actionmapping, ActionForm form, HttpServletRequest httpservletrequest, HttpServletResponse httpservletresponse) throws IOException
    {
        Calendar calendar = Calendar.getInstance();
        StringBuffer stringbuffer;
        ServletOutputStream servletoutputstream;
        HttpSession httpsession = httpservletrequest.getSession();
        //BeanEtudiant beanetudiant = (BeanEtudiant)httpsession.getAttribute("beanetudiant");
        byte abyte0[];
        int i;
        
        try
        {
                logger.debug("appel LogicWebPaiementExt\351rieur");
           stringbuffer = LogicWebPaiementExterieur.paiementExterieur(httpservletrequest, 0,0);
            if(stringbuffer == null)
            {
                logger.debug("dans if is == null");
                return actionmapping.findForward("redirectionAdresseMail");
            }
        }
        catch(Exception exception)
        {
            httpsession = httpservletrequest.getSession(false);
            String s = (String)httpsession.getAttribute("ref_etu");
            if(s != null)
            {
                logger.error((new StringBuilder()).append("Erreur lors de l'appel au paiement ext\351rieur pour l'etudiant : ").append(s).append("#").append(calendar.getTime()).append(", ").toString(), exception);
            } else
            {
                logger.error("Pas de ref_etu en session, ", exception);
                s = Long.toString(System.currentTimeMillis());
            }
            return actionmapping.findForward("error");
        }
        
        
        
        servletoutputstream = httpservletresponse.getOutputStream();
        i = 0;
        i = stringbuffer.toString().length();
        abyte0 = stringbuffer.toString().getBytes();
        servletoutputstream.write(abyte0, 0, i);
        return null;
    }

    private static final String NOM_CLASSE_COMPLET = LogicWebEtapesAction.class.getName();
    private static final String NCC = NOM_CLASSE_COMPLET;
    private static final String NOM_CLASSE = NOM_CLASSE_COMPLET.substring(NOM_CLASSE_COMPLET.lastIndexOf('.') + 1);

}
